import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 5174,
    proxy: {
      // 用户相关写操作转发到Write API
      '/api/User/register': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      '/api/User/update': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      '/api/User/delete': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      // 开单申请写操作（提交、支付、更新状态）转发到Write API
      '/api/OrderApplication/submit': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      '/api/OrderApplication/pay': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      '/api/OrderApplication/update-status': {
        target: 'http://localhost:5049',
        changeOrigin: true,
      },
      // 开单申请查询（GET请求）转发到Read API
      '/api/OrderApplication': {
        target: 'http://localhost:5029',
        changeOrigin: true,
      },
      // 用户查询操作转发到Read API
      '/api/User': {
        target: 'http://localhost:5029',
        changeOrigin: true,
      },
      // 院区信息查询转发到Read API
      '/api/HospitalArea': {
        target: 'http://localhost:5029',
        changeOrigin: true,
      },
      // 医疗项目查询转发到Read API
      '/api/MedicalProject': {
        target: 'http://localhost:5029',
        changeOrigin: true,
      },
      // 默认转发到Read API
      '/api': {
        target: 'http://localhost:5029',
        changeOrigin: true,
      },
    },
  },
})
